﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cofe.Core;
using Cofe.Core.Dynamic;
using Cofe.Core.Interfaces;
using Cofe.Core.Property;
using Cofe.Core.Service;

namespace Cofe.Data
{
    public interface IDatabaseEntryFactory 
    {       
        /// <summary>
        /// Given a property host, create an appropriate databaseEntry with all implementations in it.
        /// </summary>
        /// <param name="propertyHost"></param>
        /// <returns></returns>
        List<DatabaseEntry> CreateFullDatabaseEntry(CofeDbContext context, params IPropertyHost[] propertyHosts);

        List<Tuple<IPropertyHost, DatabaseEntry>> FindOrCreateDatabaseEntry(CofeDbContext context, params IPropertyHost[] propertyHosts);
        

        /// <summary>
        /// Given an dbentry created by ORM, reconstructed a new propertyHost that has all cached properties.     
        /// Also update several properties/extendedproperties only cached in entry.
        /// </summary>
        /// <param name="entry"></param>
        /// <returns></returns>
        IPropertyHost UpdateImpl(DatabaseEntry entry);

        /// <summary>
        /// Given an dbentry created by ORM, find the appropriate type from it's Implementations,
        /// update it's PropertyCache, and return.
        /// Also update several properties only cached in entry.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entry"></param>
        /// <returns></returns>
        T UpdateImpl<T>(DatabaseEntry dbEntry, T entry) where T : ICofeSystemInfo;
    }
}
